package zhanglu.family.socket.demo.busdemo.client1;

import org.apache.log4j.PropertyConfigurator;

import zhanglu.family.socket.bean.ErrMsg;
import zhanglu.family.socket.bean.busbean.BusMsgBean;
import zhanglu.family.socket.demo.busdemo.client1.post.PostDemo1;
import zhanglu.family.socket.demo.busdemo.client1.post.PostDemo2;

/**
 * 客户端demo
 * 
 * @author zhanglu
 * @date 2017年3月10日
 */
public class Client1Main {
    public static void main(String[] args) {
        PropertyConfigurator.configure("log4j.properties");

        ClientManager manager = ClientManager.getInstance();
        manager.startUp();

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        /*************** 测试异步消息，start *****************/
        PostDemo1 bean1 = new PostDemo1();// 消息文本
        bean1.setTest("异步消息");
        manager.post(PostDemo1.class, 1L, bean1);
        manager.post(PostDemo2.class, 2L, bean1);

        /*************** 测试异步消息，end *****************/

        /*************** 测试同步消息，start *****************/
        PostDemo2 bean2 = new PostDemo2();// 消息文本
        bean2.setTest2("同步消息");
        BusMsgBean result2 = manager.send(1250978781L, 2, bean2);

        System.out.println("同步消息,错误code是：" + result2.getErrMsg().getErrCode() + "--错误字符key是：" + result2.getErrMsg() + "--错误描述是：" + result2.getErrMsg().getErrMsg());

        if (result2.getErrMsg() == ErrMsg.NONE) {
            System.out.println("同步消息" + result2.getJsonMsg());
        }

        BusMsgBean result3 = manager.send(1250978781L, 2, bean2);

        if (result3.getErrMsg() == ErrMsg.NONE) {
            System.out.println("同步消息3" + result3.getJsonMsg());
        }
        /*************** 测试同步消息，end *****************/
    }
}
